home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1044 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  1.5 KB

  1. From: bousch@topo.ph.kcl.ac.uk (Thierry Bousch)
  2. Subject: Dangling pointers in cancelsigintrs()
  3. Date: Fri, 18 Feb 1994 13:50:30 +0100 (MET)
  4. In-Reply-To: <9402180743.AA10650@hanauma.jpl.nasa.gov> from "Howard Chu" at Feb 17, 94 11:43:07 pm
  5.  
  6. Hello Howard, you wrote:
  7.  
  8. /*
  9.  * cancelsigintrs: remove any interrupts requested by this process, called
  10.  * at process termination.
  11.  */
  12. void ARGS_ON_STACK
  13. cancelsigintrs()
  14. {
  15.     usig *ptr, *old;
  16.     short s = spl7();
  17.  
  18.     for (old=NULL, ptr=usiglst; ptr; old=ptr, ptr=ptr->next)
  19.         if (ptr->proc == curproc) {
  20.             setexc(ptr->vec, ptr->oldv);
  21.             if (old)
  22.                 old->next = ptr->next;
  23.             else
  24.                 usiglst = ptr->next;
  25.             kfree(ptr);
  26.         }
  27.     spl(s);
  28. }
  29.  
  30.  
  31. It seems that there is a potential problem with this routine: once you
  32. have freed `ptr', the `ptr->next' information is no longer available (it
  33. lies in de-allocated memory). It also seems that the routine won't work
  34. if it must unlink consecutive usig's (because `old' will point to the
  35. previous usig, which has just been deallocated). Here is a (hopefully)
  36. safe variant of the same routine:
  37.  
  38.  
  39. /*
  40.  * cancelsigintrs: remove any interrupts requested by this process, called
  41.  * at process termination.
  42.  */
  43. void ARGS_ON_STACK
  44. cancelsigintrs()
  45. {
  46.     usig *ptr, **old, *nxt;
  47.     short s = spl7();
  48.  
  49.     for (old=&usiglst, ptr=usiglst; ptr; ) {
  50.         nxt = ptr->next;
  51.         if (ptr->proc == curproc) {
  52.             setexc(ptr->vec, ptr->oldv);
  53.             *old = nxt;
  54.             kfree(ptr);
  55.             /* note that `old' does not move! */
  56.         } else {
  57.             old = &(ptr->next);
  58.         }
  59.         ptr = nxt;
  60.     }
  61.     spl(s);
  62. }
  63.  
  64.  
  65. Thierry.
  66.